﻿
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>权限角色组</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script type="text/html" id="barDemo">
            <a title="编辑" href="javascript:;" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
            <a title="权限分配" href="javascript:;" lay-event="tpower"><i class="layui-icon">&#xe631;</i></a>
            <a title="删除" href="javascript:;" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
    </script>

</head>
<body>
    <div class="layui-fluid">
        <div id="bDiv">
        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">

                                <input type="text" name="groupCode" placeholder="角色编码" autocomplete="off" class="layui-input" id="groupCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">

                                <input type="text" name="groupName" placeholder="角色名称" autocomplete="off" class="layui-input" id="groupName">
                            </div>
                        </form>
                    </div>
          
                    <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>

    var menuCode="";
    $(function () {
        menuCode = getUrlVariable("menuCode");
        BannerData(menuCode, "bDiv");
        loadData();
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                loadData();
            }
        })
    })
    function openWin() {
        InfoOpenPage("../System/UpdatePowerRole?dataId=0", "权限角色添加", "65%", "80%",true);
    }
    var currPage = 1;//首先默认值为1，防止出错

    /**
   数据加载
   **/
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var dUrl = "../System/getDataList?dataType=pRole&condition=" + conditon;
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { field: 'groupCode', title: '角色编码', width: 170 }
              , { field: 'groupName', title: '角色名称', width: 130 }
              , { field: 'memo', title: '备 注', width: 250 }
              , { field: 'createtime', title: '创建时间', width: 150 }
              , { field: 'userName', title: '创建人', width: 90 }
              , { field: 'right', title: '数据操作', toolbar: '#barDemo', width: 110, fixed: 'right' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                currPage = curr;
            }

            , url: dUrl
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [20, 30, 50]
            , limit: 20 //每页默认显示的数量
            ,id:"tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'tpower') {
                    InfoOpenPage("../System/SetRolePowers?groupCode=" + data.groupCode, data.groupName + "权限配置", "85%", '80%', false);
                } else if (obj.event == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        var info = DelData(data.id);
                        if (info.result) {
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });
                } else if (obj.event == 'edit') {
                    var webUrl='../System/UpdatePowerRole?dataId=' + data.id;
                    NewOpenPage(webUrl, data.groupName + "-编辑", "75%", '80%', "tData", currPage, dUrl);
                  
                }
                else if (obj.event == 'setPower') {
                  
                }

            });

        });
    }

    /**
    角色删除
    **/
    function DelData(dataId) {
        var info = undefined;
        $.ajax({
            url: "../System/DelRolePowers",
            data: { dataId: dataId },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {

                info = data;
            }
        });
        return info;
    }
  
</script>